package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class TravelCommend {

    public static final Integer TYPE_WEEK = 0; //周攻略
    public static final Integer TYPE_MOUTH = 1; //月攻略
    public static final Integer TYPE_STRATEGY = 2; //攻略建议


    private Long id;
    //游记id 设置成对象因为想要获取除了id之外的其他对象的信息
    private Long travelId;
    //游记推荐标题
    private String title;
    //游记推荐副标题
    private String subTitle;
    //游记推荐封面
    private String coverUrl;
    //游记推荐时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+*")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;
    //游记推荐类型
    private Integer type;

    public String getTypeDisplay() {
        if (type == TYPE_WEEK) {
            return "周推荐";
        } else if (type == TYPE_MOUTH) {
            return "月推荐";
        } else {
            return "攻略推荐";
        }

    }

    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("travelId", travelId);
        map.put("coverUrl", coverUrl);
        //格式化时间
        map.put("schedule", new SimpleDateFormat("yyyy-MM-dd").format(schedule));
        map.put("type", type);
        return JSONUtils.toJSONString(map);
    }

}